package com.hjqjl.puke;

import android.content.Context;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import androidx.annotation.LayoutRes;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.view.Window;

import com.hjqjl.puke.util.ActivityManager;
import com.orhanobut.logger.Logger;

import butterknife.ButterKnife;
import butterknife.Unbinder;

public abstract class BaseActivity extends AppCompatActivity {
    protected String CurrentClassName;
    protected Context mContext;
    private Unbinder unbinder;//官方文档只对fragment解绑了

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);// 竖屏
        setContentView(getLayoutView());
        unbinder = ButterKnife.bind(this);
        CurrentClassName = getClass().getSimpleName();
        Logger.d("BaseActivity===>" + CurrentClassName + "===>");// 打印出当前activity的名字
        mContext = this;
        ActivityManager.getInstance().addActivity(this);//添加Activity到容器中

        initData();
        processLogic();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unbinder.unbind();
        ActivityManager.getInstance().removeActivity(this);//从容器中删除Activity
    }

    /**
     * 加载布局
     */
    @LayoutRes
    protected abstract int getLayoutView();

    /**
     * 初始化数据
     */
    protected abstract void initData();

    /**
     * 逻辑处理
     */
    protected abstract void processLogic();

}
